<?php
/**
 * View  LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
    function selectable(){
	$('tr[class^="selectable"]').click(function(){
	    var id = $(this).attr('id');
	    
	    $(this).siblings().removeClass('selected');
	    $(this).addClass('selected');
	    
	    $("#location_id").val(id.substr(9,id.length));
	    
	})
    };
     
    $(document).ready(function()
    {
        var paginator =	$('#locations').pagination({
                'targetUrl' : '/admin/ajax/list/locationsmini',
                'orderField' : 'location_name',
                'orderDir' : 'asc',
                'selected' : '<?php echo $_SESSION['Live']['Location']['location_id'] ? $_SESSION['Live']['Location']['location_id'] : '' ?>'
            },selectable // CallBack
        );

        $( "#searchField" ).keyup( function() {
            if($(this).val().length >= 3)
            {
                var pagination = $('#locations').pagination({
                    'targetUrl' : '/admin/search/locationsmini/'+ $(this).val(),
                    'orderField' : 'location_name',
                    'orderDir' : 'asc',
                    'selected' : '<?php echo $_SESSION['Live']['Location']['location_id'] ? $_SESSION['Live']['Location']['location_id'] : '' ?>'
                }, selectable);
            }
            else if($(this).val().length == 0)
            {
                var paginator =	$('#locations').pagination({
                    'targetUrl' : '/admin/ajax/list/locationsmini',
                    'orderField' : 'location_name',
                    'orderDir' : 'asc',
                    'selected' : '<?php echo $_SESSION['Live']['Location']['location_id'] ? $_SESSION['Live']['Location']['location_id'] : '' ?>'
                },selectable // CallBack
                );           
            }
        }); 

	$("#new").fancybox({
	    'type' : 'ajax',
	    'showCloseButton' : false
	});
	
	// Lancio unselectable per i contatti eventualmente già presenti...
	selectable();
    });

    //]]>
</script>
<div id="content">
    
    <div id="summary" class="live">
	<div class="head">
	    <h2>Live:</h2>
	</div>
	<div class="body">
	    <table cellspacing="0" class="table">
		<tbody>
		    <tr>
			<th>Artista:</th>
			<td>
			    <strong>
				<?php
				foreach( $this->artists['main'] as $artist ) :
				    $artists_list .= $artist['artist_name'] . ', ';
				endforeach;
				?>
				<?php echo substr( $artists_list, 0, -2 ); ?>
			    </strong>
			</td>
		    </tr>
		    <?php if( count( $this->artists['openingact'] ) ): ?>
    		    <tr>
    			<th>Open-act:</th>
    			<td>
    			    <strong>
				    <?php
				    $artists_list = null;
				    foreach( $this->artists['openingact'] as $artist ) :
					$artists_list .= $artist['artist_name'] . ', ';
				    endforeach;
				    ?>
				    <?php echo substr( $artists_list, 0, -2 ); ?>				
    			    </strong>
    			</td>
    		    </tr>				
		    <?php endif; ?>
		</tbody>
	    </table>
	</div>
    </div>
    <form>
	<ul id="paging-live">
	    <li class="paging-context ">
		<table class="pgStyle1 circle2" cellspacing="0">
		    <tr>
			<td class="c">
			    <var>1</var>
			</td>
			<td class="t">
			    <b id="pagecircle1"><a href="/admin/live/artisti/id/<?php echo $this->live_id ?>">Artisti</a></b>
			</td>
			<td class="c selected">
			    <var>2</var>
			</td>
			<td class="t selected">
			    <b id="pagecircle2">Location</b>
			</td>
			<td class="c ">
			    <var>3</var>
			</td>
			<td class="t">
			    <b id="pagecircle2">Dettagli Live</b>
			</td>
			<td class="c">
			    <var>3</var>
			</td>
			<td class="t">
			    <b id="pagecircle2">Conferma</b>
			</td>				
		    </tr>
		</table>
	    </li>
	</ul>
    </form>    
    <div class="help">
	<h2>Location:</h2>
	<br/>
	    Seleziona la location del live dall'elenco.
    </div>

    <form id="form-invia" class="fab" method="post" action="/admin/live/location/id/<?php echo $this->live_id ?>">
	<ul>
	    <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
		<h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
		<p id="errorMsg">
		    <?php echo $this->errorMsg ?>
		</p>
	    </li>
	    <li id="fo2li107" class="likert col4">
		<div>
		    <table>
			<caption id="title107">
                            Tot: <strong><?php echo count( $this->locations ) ?></strong> location.
                            <div class="searchBox">
                                <label class="search">Cerca</label>
                                <input class="search" id="searchField" class="text" type="search" value="">
                            </div>                        
			</caption>
			<thead>
                            <tr>
                                <td class="pagination" colspan="4">
                                    <a class="prev" href="javascript: void(0);">&nbsp;</a>
                                    <span class="loader">Sto caricando...</span>
                                    <a class="next" href="javascript: void(0);">&nbsp;</a>
                                </td>
                            </tr>
			    <tr>
				<th class="sortable default {ref: 'location_name'}">Nome</th>
				<td class="sortable default {ref: 'location_city'}">Citt&agrave;</td>
				<td>&nbsp;</td>
			    </tr>
			</thead>
			<tbody id="locations">
			    <!-- Questo contenuto viene rimpiazzato dalla paginazione-->
			</tbody>
			<tfoot>
                            <tr>
                                <td class="pagination" colspan="4">
                                    <a class="prev" href="javascript: void(0);">&nbsp;</a>
                                    <span class="loader">Sto caricando...</span>
                                    <a class="next" href="javascript: void(0);">&nbsp;</a>
                                </td>
                            </tr>
			</tfoot>
		    </table>
		</div>
	    </li>	    
	</ul>
	<br style="clear: both" />

	<ul>
	    <li class="section">
		<h3>Oppure:</h3>
		<ul>
		    <li class="addnew">
			<a id="new" class="button" href="/admin/ajax/form/newlocation">
			    <img src="/images/admin/16x16/add-new.png" />Aggiungi Nuova Location (Veloce)
			</a>
		    </li>
		</ul>
	    </li>
	</ul>
</div>
<input type="hidden" name="location_id" id="location_id" value="<?php echo $_SESSION['Live']['Location']['location_id'] ? $_SESSION['Live']['Location']['location_id'] : '' ?>" />
<input type="hidden" name="conferma" id="conferma" value="conferma" />
<div id="formButtons">
    <button id="salva" name="salva" value="salva" class="button positive">
	<img src="/images/admin/tick.png" alt="" />Continua
    </button>
    <a id="annulla" name="annulla" value="annulla" class="button negative" href="#" >
	<img src="/images/admin/cross.png" alt="" />Annulla
    </a>
</div>
</form>